﻿namespace ExamV5.OnLineInter
{
    using ExamV5;
    using System;
    using System.Configuration;
    using System.Data;
    using System.Data.SqlClient;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    public class FrmDCItemInfo : Page
    {
        protected Button butClose;
        protected Button butDefault;
        protected HtmlForm form1;
        protected HtmlHead Head1;
        private HttpCookie httpCookie_0 = null;
        private HttpCookie httpCookie_1 = null;
        private HttpCookie httpCookie_2 = null;
        private HttpCookie httpCookie_3 = null;
        private int int_0 = 0;
        private PublicFun publicFun_0 = new PublicFun();
        protected HtmlInputHidden txtTitleInfo;

        protected void butDefault_Click(object sender, EventArgs e)
        {
            try
            {
                string[] strArray2;
                if (this.publicFun_0.RemoveHTML(this.txtTitleInfo.Value).Trim() == "")
                {
                    goto Label_03C2;
                }
                string str5 = "";
                string str3 = "";
                string str = "";
                string str4 = "";
                string cmdText = "";
                str5 = this.method_1(this.txtTitleInfo.Value);
                this.publicFun_0.ExecuteSql("delete QuestItem where DCID=" + this.int_0);
                SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
                connection.Open();
                SqlCommand command = null;
                string[] strArray = str5.Replace("。。", "∷").Split(new char[] { '∷' });
                for (int i = 0; i < strArray.Length; i++)
                {
                    if (strArray[i].Trim().Replace("&nbsp;", " ").Replace("<BR>", "") != "")
                    {
                        strArray2 = strArray[i].Replace("//", "⊥").Split(new char[] { '⊥' });
                        if ((strArray2.Length != 3) && (strArray2.Length != 2))
                        {
                            goto Label_039D;
                        }
                        if (strArray2[strArray2.Length - 1].Trim() != "写")
                        {
                            if (strArray2[1].Trim().IndexOf("#") < 1)
                            {
                                goto Label_0378;
                            }
                            if (!((strArray2[2].Trim() != "单") ? !(strArray2[2].Trim() != "多") : true))
                            {
                                goto Label_0353;
                            }
                            if (!(strArray2[2].Trim() == "单"))
                            {
                                if (strArray2[2].Trim() == "多")
                                {
                                    str4 = "N";
                                }
                            }
                            else
                            {
                                str4 = "Y";
                            }
                        }
                        else
                        {
                            str4 = "Z";
                        }
                        str3 = strArray2[0].Trim();
                        if (strArray2[strArray2.Length - 1].Trim() != "写")
                        {
                            str = strArray2[1].Trim().Replace("&nbsp;", " ").Replace("<BR>", "").Replace(" ", " ").Replace(",", "，");
                        }
                        else
                        {
                            str = "";
                        }
                        cmdText = "Insert into QuestItem(ItemTitle,ItemInfo,IsSing,DCID) Values(@ItemTitle,@ItemInfo,@IsSing,@DCID)";
                        command = new SqlCommand(cmdText, connection);
                        command.Parameters.Add("@ItemTitle", SqlDbType.VarChar, 0x1388).Value = str3;
                        command.Parameters.Add("@ItemInfo", SqlDbType.VarChar, 0x1388).Value = str;
                        command.Parameters.Add("@IsSing", SqlDbType.Char, 1).Value = str4;
                        command.Parameters.Add("@DCID", SqlDbType.Int).Value = this.int_0;
                        command.ExecuteNonQuery();
                        command.Dispose();
                    }
                }
                this.txtTitleInfo.Value = "";
                base.Response.Write("<script>alert('批量添加调查选项操作成功！');window.close();</script>");
                return;
            Label_0353:
                base.Response.Write("<script>alert('" + strArray2[0].Trim() + "格式不正确！')</script>");
                return;
            Label_0378:
                base.Response.Write("<script>alert('" + strArray2[0].Trim() + "格式不正确！')</script>");
                return;
            Label_039D:
                base.Response.Write("<script>alert('" + strArray2[0].Trim() + "格式不正确！')</script>");
                return;
            Label_03C2:
                base.Response.Write("<script>alert('请输入调查主题和选项内容！')</script>");
            }
            catch
            {
                base.Response.Write("<script>alert('在线调查选项格式不正确！')</script>");
            }
        }

        private void method_0()
        {
            this.txtTitleInfo.Value = "";
            string str = "";
            string cmdText = "select * from QuestItem where DCID=" + this.int_0;
            SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Conn"].ConnectionString);
            connection.Open();
            SqlCommand command = new SqlCommand(cmdText, connection);
            SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
            while (reader.Read())
            {
                if (reader["IsSing"].ToString() != "Y")
                {
                    if (!(reader["IsSing"].ToString() == "N"))
                    {
                        str = "写";
                        this.txtTitleInfo.Value = this.txtTitleInfo.Value + "<P>" + reader["ItemTitle"].ToString() + "//" + str + "。。</P>";
                    }
                    else
                    {
                        str = "多";
                        this.txtTitleInfo.Value = this.txtTitleInfo.Value + "<P>" + reader["ItemTitle"].ToString() + "//" + reader["ItemInfo"].ToString() + "//" + str + "。。</P>";
                    }
                }
                else
                {
                    str = "单";
                    this.txtTitleInfo.Value = this.txtTitleInfo.Value + "<P>" + reader["ItemTitle"].ToString() + "//" + reader["ItemInfo"].ToString() + "//" + str + "。。</P>";
                }
            }
            reader.Close();
            command.Dispose();
            connection.Close();
            connection.Dispose();
        }

        private string method_1(string string_0)
        {
            string_0 = string_0.Replace("<p><br>", "");
            string_0 = string_0.Replace("<p><br><br>", "");
            string_0 = string_0.Replace("<p><br><br><br>", "");
            string_0 = string_0.Replace("<p><br><br><br><br>", "");
            string_0 = string_0.Replace("<p><br />", "");
            string_0 = string_0.Replace("<p><br /><br />", "");
            string_0 = string_0.Replace("<p><br /><br /><br />", "");
            string_0 = string_0.Replace("<p><br /><br /><br /><br />", "");
            string_0 = string_0.Replace("<p>", "");
            string_0 = string_0.Replace("<p align=right>", "");
            string_0 = string_0.Replace("<p align=center>", "");
            string_0 = string_0.Replace("<p align=left>", "");
            string_0 = string_0.Replace("</p>", "");
            string_0 = string_0.Replace("\r\n", "");
            string_0 = string_0.Replace("http://", "");
            string_0 = string_0.Replace("<P><BR>", "");
            string_0 = string_0.Replace("<P><BR><BR>", "");
            string_0 = string_0.Replace("<P><BR><BR><BR>", "");
            string_0 = string_0.Replace("<P><BR><BR><BR><BR>", "");
            string_0 = string_0.Replace("<P><BR />", "");
            string_0 = string_0.Replace("<P><BR /><BR />", "");
            string_0 = string_0.Replace("<P><BR /><BR /><BR />", "");
            string_0 = string_0.Replace("<P><BR /><BR /><BR /><BR />", "");
            string_0 = string_0.Replace("<P>", "");
            string_0 = string_0.Replace("<P ALIGN=RIGHT>", "");
            string_0 = string_0.Replace("<P ALIGN=CENTER>", "");
            string_0 = string_0.Replace("<P ALIGN=LEFT>", "");
            string_0 = string_0.Replace("</P>", "");
            string_0 = string_0.Replace("HTTP://", "");
            return string_0;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.httpCookie_0 = new HttpCookie("ExamUserCode");
            this.httpCookie_0 = base.Request.Cookies["ExamUserCode"];
            this.httpCookie_1 = new HttpCookie("ExamUserName");
            this.httpCookie_1 = base.Request.Cookies["ExamUserName"];
            this.httpCookie_2 = new HttpCookie("ExamUserLevel");
            this.httpCookie_2 = base.Request.Cookies["ExamUserLevel"];
            this.httpCookie_3 = new HttpCookie("ExamDeptID");
            this.httpCookie_3 = base.Request.Cookies["ExamDeptID"];
            if ((this.httpCookie_0 != null) ? !(this.httpCookie_0.Value == "") : false)
            {
                base.Response.Cache.SetCacheability(HttpCacheability.NoCache);
                base.Response.Cache.SetNoStore();
                this.httpCookie_0.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_0.Value));
                this.httpCookie_1.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_1.Value));
                this.httpCookie_2.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_2.Value));
                this.httpCookie_3.Value = this.publicFun_0.CheckString(base.Server.UrlDecode(this.httpCookie_3.Value));
                this.int_0 = Convert.ToInt32(base.Request["ID"].ToString());
                base.Title = ConfigurationManager.ConnectionStrings["ProTitle"].ConnectionString + "---编辑调查选项信息";
                if (!base.IsPostBack)
                {
                    if (this.publicFun_0.ReturnPaperData() != "Yes")
                    {
                        base.Response.Write("<script>alert('此版本暂未授权,请拔打(0)13870606104手机号进行授权！')</script>");
                    }
                    else
                    {
                        this.method_0();
                    }
                }
            }
            else
            {
                base.Response.Write("<script language=javascript>top.location.href='../Index.htm';self.close();</script>");
            }
        }
    }
}

